checkLogin();


//获取验证码
$('#get_cart').bind('click', function () {
    var login = getCache(login_key);
    if(isEmpty(login.mobile)){
        $('#myform_mobile').css('display','block');
    }else {
        var self = $(this);
        var success = function (res) {
            self.addClass('mui-disabled').attr('disabled', true);
            var info = res.sms_time;
            $('#get_cart').text(info + 's');
            var intervarId = null;

            function count_down() {
                info--;
                if (info <= 0) {
                    clearInterval(intervarId);
                    self.removeClass('mui-disabled').removeAttr('disabled');
                    $('#get_cart').text('请重新获取');
                    return;
                }
                $('#get_cart').text(info + 's');
            }

            intervarId = setInterval(function () {
                count_down();
            }, 1000);

        }
        getData(member_captcha, comParams(), success);
    }
})


//验证表单
function getConfirmContent() {
    var name = $('#name').val();
    var mobile = $('#mobile').val();
    var move_id = $('#move_id').val();
    var str = '';
    if (name && mobile && move_id) {
        str = '<p></p><p>' + '受移交人ID：' + move_id + '</p>' + '<p>' + '受移交人姓名：' + name + '</p>' + '<p>' + '受移交人电话：' + mobile + '</p>'
        +'<p style="color: orange">注意：该操作不可逆，请谨慎操作！</p>';
    }
    return '<p>' + str + '</p>';
}
var ajaxOption = {
    url: member_move,
    method: 'POST',
    confirm: true,
    confirm_title: '请确认以下信息',
    confirm_content: ['getConfirmContent'],//用[]包起来表示该值是函数，不包则为字符串
    data: comParams(),
    success: function (res) {
        setTimeout(function () {
           logout(1);
        }, 2000);
    }
};

checkform($('#myForm'), ajaxOption);

//获取原始窗口的高度
var originalHeight=document.documentElement.clientHeight || document.body.clientHeight;
window.onresize=function(){
    //软键盘弹起与隐藏  都会引起窗口的高度发生变化
    var  resizeHeight=document.documentElement.clientHeight || document.body.clientHeight;
    if(resizeHeight*1<originalHeight*1){ //resizeHeight<originalHeight证明窗口被挤压了
        $('.sure-submit').css('display','none');
        /*$(".mui-iframe-wrapper").css('bottom','0px');*/
    }else{
        $('.sure-submit').css('display','block');
        /*$(".mui-iframe-wrapper").css('bottom','50px');*/
    }
}

$('.img_cuo').bind('click',function () {
    $('.show_alert').hide();
})

$('.get_code').bind('click',function () {

    var mobile = $('.mobile').val();
    if (mobile == undefined || mobile == null || mobile == '') {
        malert('请填写联系方式');
        return;
    }
    var success = function (res) {
        console.log(res)
        var info = res.sms_time;

        $('.get_code').text(info + 's');
        var intervarId = null;

        function count_down() {
            info--;
            if (info <= 0) {
                clearInterval(intervarId);
                $('.get_code').removeClass('mui-disabled').removeAttr('disabled');
                $('.get_code').text('请重新获取');
                return;
            }
            $('.get_code').text(info + 's');
        }

        intervarId = setInterval(function () {
            count_down();
        }, 1000);


    }
    getData(member_sms_captcha, combineParams({mobile: mobile}), success);
})

var is_mobile = function(e) {
    var status = true;
    if (!(/^1\d{10}$/.test( $(e).val()))){
        status = false;
    }
    return {
        status: status, // or false
        message: '请填写正确的手机号'
    };
}

var ajaxOption = {
    url: member_add_information,
    method: 'POST',
    data: comParams(),
    success: function (res) {
        //保存成功  将修改的电话追加到 缓存中
        var mobile = $('.mobile').val();
        var login_text = getCache(login_key);
        if(!isEmpty(login_text) && isEmpty(login_text.mobile)){
            login_text.mobile = mobile;
            console.log(login_text)
            setCache(login_key, login_text);
        }
        $('.show_alert').hide();
    }
}

checkform($('#myform_mobile'), ajaxOption);

$(function(){
    $.ajax({
        url:invite_member,
        method: 'GET',
        data:comParams(),
        success:function(res){
            if(res) {
                var imgHtml = "<img id='invite-member' src='" + res +"' style='width: 200px;height: 200px'/>";
                $(".img_qrcode").html(imgHtml);
            }
        }
    })
})